import {fileURLToPath, URL} from 'node:url';
import {defineConfig} from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
// 按需引入
import IconsResolver from 'unplugin-icons/resolver';
import Components from 'unplugin-vue-components/vite';
import AutoImport from 'unplugin-auto-import/vite';
import {ArcoResolver} from 'unplugin-vue-components/resolvers';

const root = process.cwd()

export default defineConfig({
	server: {
		host: "0.0.0.0",
		// port: 5000,
		cors: true,
		headers: {
			'Access-Control-Allow-Origin': '*'
		}
	},
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src', import.meta.url))
		},
		extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
	},
	css: {
		preprocessorOptions: {
			scss: {
				silenceDeprecations: ["legacy-js-api"],
				// api: 'modern-compiler' // or "modern", "legacy"
			},
		},
	},
	plugins: [
		vue(),
		vueJsx(),
		AutoImport({
			include: [
				/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
				/\.vue$/,
				/\.vue\?vue/ // .vue
			],
			dirs: ['./src'],
			imports: [
				'vue',
				'vue-router',
				{
					'@/hooks/useI18n': ['useI18n'],
					'@/hooks/useCache': ['useCache'],
					'@/hooks/useMessage': ['useMessage'],
				}
			], // 限定范围为 vue, vue-router
			dts: 'types/auto-import.d.ts', // 自动生成 'auto-import.d.ts'全局声明
			resolvers: [
				ArcoResolver(),
			]
		}),
		Components({
			// 按需导入组件，相关组件声明放置于 components.d.ts
			dts: './types/components.d.ts', 
			resolvers: [
				IconsResolver({
					enabledCollections: ['ep']
				}),
				ArcoResolver({
					sideEffect: true
				})
			]
		}),
	],
})
